package com.example.ida;

import java.util.Arrays;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.Toast;
import android.widget.FrameLayout.LayoutParams;

public class CameraActivity extends Activity {
	
	CameraSurface cameraS;
	ImageButton shut;
	int scw = 0;
	int sch = 0;
	LayoutParams shutPram;
	String baby = "0";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_camera);
		this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		baby = getIntent().getStringExtra("baby");
		
		this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		
		scw = getWindowManager().getDefaultDisplay().getWidth();
		sch = getWindowManager().getDefaultDisplay().getHeight();
		
		cameraS = new CameraSurface(getApplicationContext());
		cameraS.setCamAct(this);
		if(baby!=null)
		{
			cameraS.setBaby(baby);			
		}
//		Toast.makeText(getApplicationContext(), baby, Toast.LENGTH_SHORT).show();
		
		
		shut = new ImageButton(this);
		shut.setImageResource(R.drawable.shot_btn);
		shut.setBackgroundColor(Color.argb(0, 255, 255, 255));
//		shut.setTextColor(Color.rgb(255, 255, 255));
//		shut.setAlpha(80);
		
		shutPram = new LayoutParams(scw/3, 200);
		shutPram.setMargins(shutPram.width, sch-(shutPram.height/2)*3, 0, 0);
		
		FrameLayout lf = new FrameLayout(this);
		lf.addView(cameraS);
		
		shut.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				cameraS.getPicture();				
			}
		});
		lf.addView(shut, shutPram);
		setContentView(lf);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		new MenuIda(this, item);

		return super.onOptionsItemSelected(item);
	}
}
